<template>
  <div>
    <Form ref="form1" :model="formItem" :label-width="120">
      <Row v-show="!switchFlag" class="query-form" style="padding-top: 15px">
        <Col span="8">
          <FormItem label="姓名：">
            <Input class="query-form-el" v-model="formItem.userName"></Input>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="登录账号：">
            <Input class="query-form-el" v-model="formItem.loginId"></Input>
          </FormItem>
        </Col>
        <Col span="8">
          <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
          <Button @click="reset" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form" style="padding-top: 15px">
        <Col span="8">
          <FormItem label="姓名：">
            <Input class="query-form-el" v-model="formItem.userName"></Input>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="登录账号：">
            <Input class="query-form-el" v-model="formItem.loginId"></Input>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="组织机构选择：">
            <cascader-dom ref="childOrg" class="query-form-el" :orgTree='true' @setOrgInfo='setOrgInfo'
                          :rootAffordIf="true" :department="true"></cascader-dom>
          </FormItem>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form">
        <Col span="8">
          <FormItem label="组织机构搜索：">
            <Input class="query-form-el" placeholder="输入公司名称" v-model="formItem.companyName"></Input>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="岗位：">
            <Input class="query-form-el" placeholder="输入岗位名称" v-model="formItem.positionName"></Input>
          </FormItem>
        </Col>
        <Col span="8">
          <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
          <Button @click="reset" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
        </Col>
      </Row>
      <!--            <Row class="query-form" v-show="!model">
                      <Col span="24">
                          <Button size="large" type="success" class="ivu-btn-add" icon="md-add" @click="modaltage()">新增
                          </Button>
                      </Col>
                  </Row> -->
    </Form>

    <Table ref='table' :height="tableHeight" :loading="buttonLoading" class="table" no-data-text="没有查询到相关数据!"
           highlight-row stripe border :columns="columns3" width="100%" :data="data1" size="small">
    </Table>
    <Page :total="pagedata.total" :fromPage="pagedata.fromPage" :pageSize="pagedata.pageSize"
          @on-change="pageChange" @on-page-size-change='sizeChange' show-total show-sizer show-elevator/>

    <Modal v-model="modal2" :transfer=false :width=600 :closable="false" :mask-closable="false"
           title="添加">
      <Form ref="formCustom" :model="formCustom" :rules="ruleCustom" label-position="top">
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="姓名" prop="userName">
              <Input type="text" v-model="formCustom.userName"></Input>
            </FormItem>
          </Col>
          <Col span="11">
            <FormItem label="登录账号" prop="loginId">
              <Input type="text" v-model="formCustom.loginId"></Input>
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="组织机构" prop="orgId">
              <cascader-dom ref="child" :orgTree="true" :currentOrgId="orgId" :currentOrgName="orgName"
                            :department="true" @setOrgInfo="orgNamesetOrgInfo" :rootAffordIf="true"></cascader-dom>
            </FormItem>
          </Col>
          <Col span="11">
            <FormItem label="岗位" prop="positionId">
              <Select v-model="formCustom.positionId" @on-open-change="queryPosition">
                <Option v-for="item in positions" :key="item.positionId" :value="item.positionId"
                        :label="item.positionName"></Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="手机" prop="mobileNumber">
              <Input type="text" v-model="formCustom.mobileNumber"></Input>
            </FormItem>
          </Col>
          <Col span="11">
            <FormItem label="固定电话" prop="contactNumber">
              <Input type="text" v-model="formCustom.contactNumber"></Input>
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="密码：" prop="password">
              <Input type="password" v-model="formCustom.password"></Input>
            </FormItem>
          </Col>
          <Col span="11">
            <FormItem label="确定密码：" prop="password1">
              <Input type="password" v-model="formCustom.password1"></Input>
            </FormItem>
          </Col>
        </Row>
      </Form>
      <div slot="footer">
        <Button class='ivu-btn-save' @click="modalok()">确定</Button>
        <Button type="text" class='ivu-btn-cancel' @click="modalcancel">取消</Button>
      </div>
    </Modal>

    <Modal v-model="modal3" :transfer=false :width=600 :closable="false" :mask-closable="false"
           title="修改">
      <Form ref="modifyFormCustom" :model="modifyFormCustom" :rules="modifyRuleCustom" label-position="top">
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="姓名" prop="userName">
              <Input type="text" v-model="modifyFormCustom.userName"></Input>
            </FormItem>
          </Col>
          <Col span="11">
            <FormItem label="登录账号" prop="loginId">
              <Input type="text" v-model="modifyFormCustom.loginId"></Input>
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="组织机构" prop="orgId">
              <cascader-dom ref="child1" :orgTree="true" :currentOrgId="orgId" :currentOrgName="orgName"
                            :department="true" @setOrgInfo="orgNamemodifysetOrgInfo"
                            :rootAffordIf="true"></cascader-dom>
            </FormItem>
          </Col>
          <Col span="11">
            <FormItem label="岗位" prop="positionId">
              <Select v-model="modifyFormCustom.positionId" @on-open-change="queryModifyPosition">
                <Option v-for="item in positions" :key="item.positionId" :value="item.positionId"
                        :label="item.positionName"></Option>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="手机" prop="mobileNumber">
              <Input type="text" v-model="modifyFormCustom.mobileNumber"></Input>
            </FormItem>
          </Col>
          <Col span="11">
            <FormItem label="固定电话" prop="contactNumber">
              <Input type="text" v-model="modifyFormCustom.contactNumber"></Input>
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="密码：" prop="password">
              <Input type="password" v-model="modifyFormCustom.password"></Input>
            </FormItem>
          </Col>
          <Col span="11">
            <FormItem label="确定密码：" prop="password1">
              <Input type="password" v-model="modifyFormCustom.password1"></Input>
            </FormItem>
          </Col>
        </Row>
      </Form>
      <div slot="footer">
        <Button class='ivu-btn-save' @click="modifyModalok()">确定</Button>
        <Button type="text" class='ivu-btn-cancel' @click="modalcancel">取消</Button>
      </div>
    </Modal>

    <Modal v-model="orgModal" title="分配兼职机构" :styles="{height:'500px'}" class-name='limit-height-dialog'>
      <Tree ref="userOrgInfoTree" :data="orderTree" :load-data="loadData" show-checkbox multiple></Tree>
      <div slot="footer">
        <Button class='ivu-btn-save' @click="saveUserOrgs()">确定</Button>
        <Button type="text" class='ivu-btn-cancel' @click="cancelUserOrgs">取消</Button>
      </div>
    </Modal>

    <Modal v-model="roleModal" footer-hide title="角色列表" :styles="{height:'500px'}" class-name='limit-height-dialog'>
      <Table ref='table' :loading="roleTableLoading" class="table" no-data-text="没有查询到相关数据!"
             highlight-row stripe border :columns="userRoleColumn" width="100%" :data="userRoles" size="small">
      </Table>
    </Modal>
  </div>
</template>

<script>
import cascaderDom from "../../../components/cascader-dom.vue"
import {Api} from '../../../api/index.js'
import {sessionStorage} from '@/common/cacheUtils.js';
import zTree from "@/components/ztree.vue"

export default {
  props: ['model', 'companyId'],
  components: {cascaderDom, zTree},
  data() {
    return {
      orgModal: false,
      isHead: true,
      ztreeObj: null,
      positions: [],
      userRoles: [],
      switchFlag: false,
      orgId: '',
      orgName: '',
      tableHeight: '',
      buttonLoading: false,
      roleTableLoading: false,
      roleModal: false,
      selectedUserId: "",
      formItem: {
        userName: "",
        loginId: "",
        orgId: ""
      },
      formCustom: {
        userName: '',
        loginId: '',
        orgId: '',
        password: '',
        positionId: '1'
      },
      modifyFormCustom: {
        userName: '',
        loginId: '',
        orgId: '',
        password: '',
        positionId: '1'
      },
      pagedata: {
        total: 0, //总条数
        fromPage: 1,//从n条开始
        pageSize: 10//每页多少条
      },
      tage: false,
      modal2: false,
      modal3: false,
      modifyRuleCustom: {
        userName: [{
          required: true,
          message: '  ',
          trigger: 'blur'
        }],
        mobileNumber: [{
          validator: (rule, value, callback) => {
            if (!(/^1[3456789]\d{9}$/.test(this.modifyFormCustom.mobileNumber))) {
              callback(' ');
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'blur'
        }],
        positionId: [{
          validator: (rule, value, callback) => {
            if (this.modifyFormCustom.positionId == null || this.modifyFormCustom.positionId == '' || this.formCustom.positionId == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        password: [{
          validator: (rule, value, callback) => {
            if (value == "" || value == "undefined" || value == undefined)
              callback();
            var regex = new RegExp("(?=.*[0-9])(?=.*[a-zA-Z]).{9,16}");
            if (value.length < 9 || value.length > 16) {
              callback(new Error("请输入9~16位密码"));
            } else if (!regex.test(value)) {
              callback(new Error("密码必须同时包含字母、数字且至少9位"));
            } else {
              callback();
            }
          },
          required: false,
          trigger: 'blur'
        }],
        password1: [{
          validator: (rule, value, callback) => {
            if (this.modifyFormCustom.password != this.modifyFormCustom.password1) {
              callback('两次密码输入不一致')
            } else {
              callback()
            }
          },
          required: false,
          trigger: 'blur'
        }],
      },
      ruleCustom: {
        userName: [{
          required: true,
          message: '  ',
          trigger: 'blur'
        }],
        loginId: [{
          validator: (rule, value, callback) => {
            if (!(/^1[3456789]\d{9}$/.test(this.formCustom.loginId))) {
              callback(new Error("请输入手机号"));
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'blur'
        }],
        mobileNumber: [{
          validator: (rule, value, callback) => {
            if (!(/^1[3456789]\d{9}$/.test(this.formCustom.mobileNumber))) {
              callback(' ');
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'blur'
        }],
        positionId: [{
          validator: (rule, value, callback) => {
            if (this.formCustom.positionId == null || this.formCustom.positionId == '' || this.formCustom.positionId == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        password: [{
          validator: (rule, value, callback) => {
            if (value == "")
              callback();
            var regex = new RegExp("(?=.*[0-9])(?=.*[a-zA-Z]).{9,16}");
            if (value.length < 9 || value.length > 16) {
              callback(new Error("请输入9~16位密码"));
            } else if (!regex.test(value)) {
              callback(new Error("密码必须同时包含字母、数字且至少9位"));
            } else {
              callback();
            }
          },
          required: true,
          trigger: 'blur'
        }],
        password1: [{
          validator: (rule, value, callback) => {
            if (this.formCustom.password != this.formCustom.password1) {
              callback('两次密码输入不一致')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'blur'
        }],
      },
      userRoleColumn: [
        {
          type: 'index',
          title: "序号",
          width: 80,
          align: 'center'
        },
        {
          title: '角色名称',
          minWidth: 100,
          align: 'center',
          key: 'roleName'
        },
        {
          title: '操作',
          fixed: 'right',
          align: 'center',
          width: 80,
          render: (h, params) => {
            return h('div', [
              h('A', {
                props: {type: 'primary', size: 'small'},
                style: {marginRight: '5px'},
                on: {
                  click: () => {
                    this.$Modal.confirm({
                      title: '提示信息',
                      content: '<p>若该人员录入的数据需要后期维护，请先创建工作交接信息后在删除账号。</p>',
                      okText: '确认',
                      cancelText: '取消',
                      onOk: () => {
                        this.deleteUserRoleByUserAndRoleId(params.row.userId, params.row.roleId, params.index);
                      }
                    });
                  }
                }
              }, '删除'),
            ]);
          }
        }
      ],
      columns3: [
        {
          // type: 'index',
          title: "序号",
          width: 80,
          align: 'center',
          render: (h, params) => {
            return h('span', params.index + (this.pagedata.fromPage - 1) * this.pagedata.pageSize + 1);
          }
        },
        {
          title: '姓名',
          width: 100,
          align: 'center',
          key: 'userName'
        },
        {
          title: '登录账号',
          width: 100,
          align: 'center',
          key: 'loginId',
          render: (h, params) => {
            return h('div', [
              h('span', {
                style: {
                  color: 'blue',
                  cursor: 'pointer'
                },
                on: {
                  click: () => {
                    if (!this.model) {
                      this.modify(params)
                    }
                  }
                }
              }, params.row.loginId)
            ])
          }
        },
        {
          title: '二级集团',
          minWidth: 200,
          align: 'center',
          key: 'twoLevelOrgName'
        },
        {
          title: '公司',
          minWidth: 200,
          align: 'center',
          key: 'companyName'
        },
        {
          title: '部门',
          minWidth: 200,
          align: 'center',
          key: 'orgName'
        },
        {
          title: '岗位',
          minWidth: 150,
          align: 'center',
          key: 'positionName'
        },
        {
          title: '操作',
          fixed: 'right',
          align: 'center',
          width: this.model ? 80 : 300,
          render: (h, params) => {
            if (this.model) {
              return h('div', [
                h('A', {
                  props: {type: 'primary', size: 'small'},
                  style: {marginRight: '5px'},
                  on: {
                    click: () => {
                      this.save(params.row);
                    }
                  }
                }, '选择'),
              ]);
            } else {
              return h('div', [
                h('A', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    fontSize: '14px'
                  },
                  on: {
                    click: () => {
                      this.modify(params)
                    }
                  }
                }, '修改'),
                h('Divider', {
                  props: {
                    type: 'vertical',
                  }
                }, ''),
                h('A', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    fontSize: '14px'
                  },
                  on: {
                    click: () => {
                      this.selectedUserId = params.row.userId;
                      this.orderTree = [
                        {
                          orgId: '18000000',
                          title: '北京金隅集团股份有限公司',
                          expand: false,
                          loading: true,
                          checked: false,
                          children: [],
                        }
                      ]
                      this.queryUserOrgsByUserIdAndOrg(params.row.userId, this.orderTree[0].orgId, this.orderTree[0]);
                    }
                  }
                }, '分配兼职机构'),
                h('Divider', {
                  props: {
                    type: 'vertical',
                  }
                }, ''),
                h('A', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    fontSize: '14px'
                  },
                  on: {
                    click: () => {
                      this.queryRoleByUserId(params.row.userId);
                    }
                  }
                }, '角色列表'),
                h('Divider', {
                  props: {
                    type: 'vertical',
                  }
                }, ''),
                h('A', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    fontSize: '14px',
                    color: 'red'
                  },
                  on: {
                    click: () => {
                      this.$Modal.confirm({
                        title: '提示信息',
                        content: '<p>删除该人员</p>',
                        okText: '确认',
                        cancelText: '取消',
                        onOk: () => {
                          this.remove(params)
                        }
                      });
                    }
                  }
                }, '删除')
              ]);
            }
          }
        }
      ],
      data1: [],
      orderTree: [
        {
          orgId: -1,
          title: '组织机构',
          expand: false,
          checked: false,
          loading: true,
          children: [],
        }
      ],
      setingTree: {
        check: {
          enable: true
        },
        data: {
          simpleData: {
            enable: true,
            idKey: "id",
            pIdKey: "parentId",
          },
          key: {
            children: "childList"
          },
        },
        view: {
          showIcon: false,
          showLine: true
        }
      },
    }
  },
  watch: {
    "modal2": function (qw, er) {
      if (qw && this.tage) {
        setTimeout(() => {
          this.$refs.child.setCurrentOrg();
        }, 100)
      } else {
        this.$refs.child.resetCurrentOrg();
      }
    },
    companyId(newVal, oldVal) {
      this.query()
    },
  },
  mounted: function () {
    if (this.model) {
      this.tableHeight = 400
    } else {
      this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
    }
    this.query()
  },
  methods: {
    loadData(item, callback) {
      this.$http.get(Api.queryUserOrgsByUserId + "/" + this.selectedUserId + "/" + item.orgId).then(function (res) {
        if (res.data.result == true) {
          let checked = item.checked;
          item.checked = false;
          item.selected = false;
          let hasChecked = false;
          res.data.data.forEach(item1 => {
            item1.loading = false;
            item1.expand = false;
            item1.children = [];
            if (item1.checked == 'false') {
              item1.checked = false;
            } else {
              item1.checked = true;
              hasChecked = true;
            }
          })
          if (res.data.data.length == 0 || !hasChecked) {
            item.checked = checked;
          }
          callback(res.data.data);
        }
      }, function (res) {
        this.$Message.error('请求失败');
      });
    },
    queryRoleByUserId(userId) {
      this.roleModal = true;
      this.$http.get(Api.queryUserRoleByUserId + "/" + userId).then(function (res) {
        if (res.data.retCode == "S") {
          this.userRoles = res.data.data;
        }
      }, function (res) {
        this.$Message.error('请求失败');
      });
    },
    deleteUserRoleByUserAndRoleId(userId, roleId, index) {
      this.$http.delete(Api.deleteUserRoleByUserAndRoleId + "/" + userId + "/" + roleId).then(function (res) {
        if (res.data.retCode == "S") {
          this.userRoles.splice(index, 1);
        }
      }, function (res) {
        this.$Message.error('请求失败');
      });
    },
    queryUserOrgsByUserIdAndOrg(userId, orgId, item) {
      this.orgModal = true;
      item.loading = true;
      this.$http.get(Api.queryUserOrgsByUserId + "/" + userId + "/" + orgId).then(function (res) {
        if (res.data.result == true) {
          item.loading = false;
          item.expand = true;
          res.data.data.forEach(item1 => {
            item1.loading = false;
            item1.expand = false;
            if (item1.checked == 'false') {
              item1.checked = false;
            } else {
              item1.checked = true;
            }
            item1.children = [];
          })
          item.children = res.data.data;
        }
      }, function (res) {
        this.$Message.error('请求失败');
      });
    },
    saveUserOrgs() {
      let checkNode = '';
      this.$refs.userOrgInfoTree.getCheckedAndIndeterminateNodes().forEach(item => {
        if (item.orgType == '2' && (item.orgLevel == '12' || item.orgLevel == '13' || item.orgLevel == '0200100005000000007' || item.orgLevel == '' || item.orgLevel == null)) {
          checkNode += (item.orgId + "_1,");
        } else {
          checkNode += (item.orgId + "_0,");
        }
      })
      let param = {'orgId': checkNode};
      this.$http.post(Api.addUserOrg + "/" + this.selectedUserId,
          param, {emulateJSON: true}).then(function (res) {
        this.orgModal = false;
        this.$Message.info('保存成功');
      }, function (res) {
        this.$Message.error('请求失败');
      });
    },
    cancelUserOrgs() {
      this.orgModal = false;
    },
    handleCreated(ztreeObj) {
      this.ztreeObj = ztreeObj;
    },
    save(row) {
      this.$emit('getSelectModelData', row);
    },
    switchQuery(flag) {
      this.switchFlag = flag;
      if (!this.switchFlag) {
        this.tableHeight = this.tableHeight + 44;
      } else {
        this.tableHeight = this.tableHeight - 44;
      }
    },
    queryPosition() {
      let data = {
        fromPage: 1,
        pageSize: 1000,
        orgId: this.formCustom.orgId
      }
      this.$http.get(Api.queryPosition, {
        params: data
      }).then(res => {
        this.positions = res.data.data;
      })
    },
    orgNamesetOrgInfo(data) {
      this.formCustom.orgId = data[data.length - 1];
    },
    queryModifyPosition() {
      let data = {
        fromPage: 1,
        pageSize: 1000,
        orgId: this.modifyFormCustom.orgId
      }
      this.$http.get(Api.queryPosition, {
        params: data
      }).then(res => {
        this.positions = res.data.data;
      })
    },
    orgNamemodifysetOrgInfo(data) {
      this.modifyFormCustom.orgId = data[data.length - 1];
    },
    setOrgInfo(data) {
      this.formItem.orgId = data[data.length - 1];
    },
    sizeChange(size) {
      this.pagedata.pageSize = size
      this.query()
    },
    pageChange(pagenum) {
      this.pagedata.fromPage = pagenum
      this.query()
    },
    query() {
      this.buttonLoading = true
      let data = {};
      data.fromPage = this.pagedata.fromPage;
      data.pageSize = this.pagedata.pageSize;

      data = Object.assign(data, JSON.parse(JSON.stringify(this.formItem)));
      data.orgId = this.formItem.orgId;
      if (this.model) {
        data.companyId = this.companyId
      } else if (this.formItem.companyName == "" || this.formItem.companyName == undefined) {
        if (sessionStorage('userId').getObject('userId').loginId != 'superadmin')
          data.companyName = sessionStorage('userId').getObject('userId').companyName;
      }
      // let url="http://localhost:30032/envinfo/SaStaffEnvinfo/all"
      let url = Api.queryUser
      this.$http.get(url, {
        params: data
      }).then(res => {
        res.data.data.map(i => {
          if (i.orgInfo != null) {
            i.orgName = i.orgInfo.orgName;
            i.orgId = i.orgInfo.orgId;
            if (i.position != null) {
              i.positionId = i.position.positionId
              i.positionName = i.position.positionName
            }
          }
        })
        this.pagedata.total = res.data.total;
        this.data1 = res.data.data;
        this.buttonLoading = false
      }).catch(e => {
        this.$Message.error('请求失败');
      })
    },
    reset() {
      this.formItem = {
        userName: "",
        loginId: "",
        orgId: "",
      };
      this.$refs.childOrg.resetCurrentOrg();
      this.query();
    },
    modaltage() {
      this.formCustom = {};
      this.$set(this.formCustom, 'userName', '');
      this.$set(this.formCustom, 'loginId', '');
      this.$set(this.formCustom, 'mainCompanyName', '');
      this.$set(this.formCustom, 'mainOrgName', '');
      this.$set(this.formCustom, 'password', "");
      this.$set(this.formCustom, 'password1', "");
      this.$set(this.formCustom, 'mobileNumber', '');
      this.$set(this.formCustom, 'contactNumber', '');
      this.modal2 = true;
    },
    modify(params) {
      this.positions = [];
      this.positions.push({positionId: params.row.positionId, positionName: params.row.positionName})
      this.tage = true;
      this.orgId = params.row.orgId;
      this.orgName = params.row.orgName,
          this.modifyFormCustom = {};
      this.$set(this.modifyFormCustom, 'userId', params.row.userId);
      this.$set(this.modifyFormCustom, 'userName', params.row.userName);
      this.$set(this.modifyFormCustom, 'positionName', params.row.positionName);
      this.$set(this.modifyFormCustom, 'positionId', params.row.positionId);
      this.$set(this.modifyFormCustom, 'loginId', params.row.loginId);
      this.$set(this.modifyFormCustom, 'orgId', params.row.orgId);
      this.$set(this.modifyFormCustom, 'orgName', params.row.orgName);
      this.$set(this.modifyFormCustom, 'mobileNumber', params.row.mobileNumber);
      this.$set(this.modifyFormCustom, 'contactNumber', params.row.contactNumber);
      setTimeout(() => {
        this.$refs.child1.setCurrentOrg();
      }, 100)
      this.modal3 = true;
    },
    remove(params) {
      this.$http.get(Api.deleteUser + '/' + params.row.userId).then(res => {
        this.$Message.success('删除成功!');
        this.query();
      }).catch(e => {
        this.$Message.error('请求失败');
      })
      this.$http.get(Api.deleteTaskByUserId + '/' + params.row.userId).then(res => {
      }).catch(e => {
      })
    },
    modalok() {
      this.$refs["formCustom"].validate((valid) => {
        if (valid) {
          this.formCustom.createUserId = sessionStorage('userId').getObject('userId').userId;
          this.formCustom.orgInfo = {"orgId": this.formCustom.orgId};
          this.formCustom.position = {"positionId": this.formCustom.positionId};
          delete this.formCustom['orgId'];
          delete this.formCustom['positionId'];
          this.$http.post(Api.addUser, this.formCustom).then(res => {
            this.modal2 = false
            this.modal3 = false
            this.$Message.success('成功!');
            this.query();
          }).catch(e => {
            this.$Message.error('请求失败');
          })
        } else {
          this.$Message.error('不能为空!');
        }
      })
    },
    modifyModalok() {
      this.$refs["modifyFormCustom"].validate((valid) => {
        if (valid) {
          if (this.modifyFormCustom.loginId == sessionStorage('userId').getObject('userId').loginId) {
            let data = sessionStorage('userId').getObject('userId')
            sessionStorage('userId').del('userId');
            data.mobileNumber = this.modifyFormCustom.mobileNumber;
            data.position.positionId = this.modifyFormCustom.positionId;
            data.orgInfo.orgId = this.modifyFormCustom.orgId;
            let data1 = JSON.stringify(data);
            sessionStorage('userId').set('userId', data1);
          }
          this.modifyFormCustom.updateUserId = sessionStorage('userId').getObject('userId').userId;
          this.modifyFormCustom.orgInfo = {"orgId": this.modifyFormCustom.orgId};
          this.modifyFormCustom.position = {"positionId": this.modifyFormCustom.positionId};
          delete this.modifyFormCustom['orgId'];

          this.$http.post(Api.updateUser, this.modifyFormCustom).then(res => {
            this.modal2 = false
            this.modal3 = false
            this.$Message.success('成功!');
            this.query();
          }).catch(e => {
            this.$Message.error('请求失败');
          })
        } else {
          this.$Message.error('不能为空!');
        }
      })
    },
    modalcancel() {
      this.modal3 = false
      this.tage = false
      this.modal2 = false
    },
  }

}
</script>

<style lang='css' scoped>
@import '../../../index.css';

</style>
